import request from '@/utils/request';
import { AxiosPromise } from 'axios';

/**
 * 获取后台开关
 * @returns {*}
 */
export const sseEnabled = (): AxiosPromise<any> => {
  return request({
    url: '/resource/sse/getEnabled',
    method: 'get'
  });
};

/**
 * 指定发送信息
 * @param userId
 * @param message
 * @returns {*}
 */
export const sseSend = (userId: number | string, message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/sse/send?userId=' + userId + '&message=' + message,
    method: 'get'
  });
};

/**
 * 全部发送信息
 * @param message
 * @returns {*}
 */
export const sseSendAll = (message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/sse/sendAll?message=' + message,
    method: 'get'
  });
};

/**
 * 订阅主题
 * @param topic
 * @returns {*}
 */
export const sseSubscribe = (topic: string): AxiosPromise<any> => {
  return request({
    url: '/resource/sse/subscribe?topic=' + topic,
    method: 'get'
  });
};

/**
 * 群发SSE订阅消息
 * @param topic
 * @param userIds
 * @param message
 * @returns {*}
 */
export const ssePublish = (topic: string, userIds: (number | string)[], message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/sse/publish?topic=' + topic + '&userIds=' + userIds + '&message=' + message,
    method: 'get'
  });
};

/**
 * 群发SSE订阅消息
 * @param topic
 * @param message
 * @returns {*}
 */
export const ssePublishAll = (topic: string, message: string): AxiosPromise<any> => {
  return request({
    url: '/resource/sse/publishAll?topic=' + topic + '&message=' + message,
    method: 'get'
  });
};
